package tech.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import tech.aistar.entity.Job;
import tech.aistar.entity.JobType;
import tech.aistar.service.IJobService;
import tech.aistar.service.IJobTypeService;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Controller
@RequestMapping("/recruitinfo")

public class RecruitController {

    @Autowired
    private IJobService jobService;

    @Autowired
    private IJobTypeService jobTypeService;

    @GetMapping("/jobsearch")
    public String jobsearch(HttpServletRequest request,String name,Integer typeId){
        //获取后台所有的产品的数据
        List<Job> jobList = jobService.findAll(name,typeId);

        //放入到request作用域中
        request.setAttribute("jobList",jobList);

        //获取所有的产品类型的数据
        List<JobType> typeList = jobTypeService.findAll();

        request.setAttribute("typeList",typeList);

        //为了进行产品类型的数据回显的功能 - 需要将typeId继续传回到页面
        request.setAttribute("typeId",typeId);
        request.setAttribute("name",name);

        return "recruitinfo/jobsearch";
    }

    @GetMapping("/del")
    public String del(Integer id) {
        jobService.delById(id);
        return "redirect:/recruitinfo/jobsearch";
    }

    @GetMapping("/jobsearch1")
    public String jobsearch1(){
        return "recruitinfo/jobsearch1";
    }

    @GetMapping("/jobinfo")
    public String jobinfo() {
        return "recruitinfo/jobinfo";
    }

    @GetMapping("/jobinfo1")
    public String jobinfo1() {
        return "recruitinfo/jobinfo1";
    }

    @GetMapping("/jobinfo2")
    public String jobinfo2(HttpServletRequest request) {
        //获取后台所有的产品的数据
        List<Job> jobList = jobService.findAll(null,null);

        //放入到request作用域中
        request.setAttribute("jobList",jobList);

        return "recruitinfo/jobinfo2";
    }

}
